package com.thrd.taiexhibition.model;

import com.alibaba.fastjson.JSON;
import com.thrd.basicframework.http.OkHttpUtils;
import com.thrd.basicframework.http.callback.ThrdCallBack;
import com.thrd.taiexhibition.bean.BeanEnterprationDown;
import com.thrd.taiexhibition.bean.BeanEnterprationInfo;
import com.thrd.taiexhibition.bean.DayEnterprationInfo;
import com.thrd.taiexhibition.callback.MvpCallback;
import com.thrd.taiexhibition.utils.Constant;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: ${唐杰}
 * @date: 2021/4/1
 * 企业产品详情
 */
public class EnterpriseInfoModel {
    public static final String TAG="EnterpriseInfoModel";


    /**
     * 获取企业信息
     */
    public void getEnterpriseInfo(String id,final MvpCallback<List<DayEnterprationInfo>> mvpCallback) {
        OkHttpUtils.post().url(Constant.HTTP_ENTERPRISE_INFO)
                .tag(TAG)
                .addParams("ProductId", id)
                .build().execute(new ThrdCallBack<List<DayEnterprationInfo>>() {
            @Override
            public void onFailed(String e, int code) {
                mvpCallback.onFailed(e, code);
            }

            @Override
            public void onResponse(List<DayEnterprationInfo> response, int id) {
                mvpCallback.onSuccess(response);
            }

            @Override
            public List<DayEnterprationInfo> onJson(String s) {
                BeanEnterprationInfo mBeanEnterprationInfo= JSON.parseObject(s, BeanEnterprationInfo.class);
                List<DayEnterprationInfo> mDayEnterprationList=new ArrayList<>();

                DayEnterprationInfo mDayEnterprationInfo=new DayEnterprationInfo();
                mDayEnterprationInfo.setImageBg(mBeanEnterprationInfo.getProductShowImg());
                mDayEnterprationInfo.setType(0);
                mDayEnterprationInfo.setVideoPath(mBeanEnterprationInfo.getProductVideo());
                mDayEnterprationInfo.setProductName(mBeanEnterprationInfo.getProductName());
                mDayEnterprationList.add(mDayEnterprationInfo);

                DayEnterprationInfo mDayData=new DayEnterprationInfo();
                mDayData.setImageBg(mBeanEnterprationInfo.getProductDetailImg());
                mDayData.setType(2);
                mDayEnterprationList.add(mDayData);

                DayEnterprationInfo mDaySideslip=new DayEnterprationInfo();
                mDaySideslip.setType(1);
                mDaySideslip.setThComProductContentSideslip(mBeanEnterprationInfo.getThComProductContentSideslip());
                mDayEnterprationList.add(mDaySideslip);

                List<BeanEnterprationDown> mEnterprationList = mBeanEnterprationInfo.getThComProductContentDropDown();
                if(mEnterprationList!=null&&mEnterprationList.size()>0){
                    for (BeanEnterprationDown down:mEnterprationList){
                        DayEnterprationInfo mDayInfo=new DayEnterprationInfo();
                        mDayInfo.setImageBg(down.getProductDetailImg());
                        mDayInfo.setType(2);
                        mDayEnterprationList.add(mDayInfo);
                    }
                }

                return mDayEnterprationList;
            }
        });
    }
}
